package 界面.弹窗

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import 界面.组件.按钮.取消图标按钮
import 界面.组件.按钮.确认图标按钮

@Composable
fun 下拉菜单(显示 : Boolean,
             响应销毁 : () -> Unit,
             内容 : @Composable ColumnScope.() -> Unit){
    DropdownMenu(显示,响应销毁, modifier = Modifier.background(MaterialTheme.colorScheme.surface)){
        内容()
    }
}

@Composable
fun 下拉菜单分割线(){
    Spacer(Modifier.height(1.dp).fillMaxWidth()
        .background(MaterialTheme.colorScheme.outlineVariant))
}

@Composable
fun 下拉菜单项目(text : String, icon : ImageVector ?= null, onClick : ()-> Unit){
    DropdownMenuItem(text = {
        Text(text, color = MaterialTheme.colorScheme.onSurface,
            style = MaterialTheme.typography.bodyMedium)
    }, leadingIcon = {
        if (icon != null) Icon(icon, "", modifier = Modifier.size(15.dp))
    }, onClick = {

        onClick()
    }, contentPadding = PaddingValues(start = if (icon != null) 15.dp else 10.dp, end = 30.dp),
        modifier = Modifier.height(45.dp))
}

/**
 * @param icon 图标生成 大小为 15.dp
 */
@Composable
fun 下拉菜单项目2(name : String,
                 icon : @Composable ()->Unit,clickable: () -> Unit){
    DropdownMenuItem(text = {
        Text(name, color = MaterialTheme.colorScheme.onSurface,
            style = MaterialTheme.typography.bodyMedium)
    }, leadingIcon = {
        Box(Modifier.size(15.dp)){
            icon()
        }
    }, onClick = {
        clickable()
    },
        contentPadding = PaddingValues(start = 15.dp, end = 30.dp),
        modifier = Modifier.height(45.dp))
}


// ---




// --

/**
 * 以下拉框的形式显示确否删除
 */
@Composable
fun 下拉删除确认(show : Boolean,onDismiss : (isDelete : Boolean)->Unit){
    下拉菜单(show,{onDismiss(false)}){
        Column(Modifier.padding(20.dp,15.dp)){

            Text( "删除?" ,
                style = MaterialTheme.typography.titleMedium,
                color = MaterialTheme.colorScheme.error)

            Spacer(Modifier.height(15.dp))

            Row(Modifier.fillMaxWidth()){
                取消图标按钮 {
                    onDismiss(false)
                }
                Spacer(Modifier.width(15.dp))
                确认图标按钮(MaterialTheme.colorScheme.error){
                    onDismiss(true)
                }
            }


        }
    }
}